import React, { Component } from 'react'
import { Context  } from '../Form/FormContext'
export default class Input extends Component {
  static defaultProps = {
    type:'text',
    autoComplete:'new-passwords'
  }
  static contextType = Context;
  shouldComponentUpdate(nextProps,nextState){
      console.log(nextProps)
      console.log('更新了吗')
      if(nextProps === this.props)return false
      return true
  }
  changeVal = e=>{
    this.context.changeFormData(e.target.name,e.target.value)
  }
  render() {
    console.log('更新渲染了，input',this.props.name)
    return (
      <input 
      type={this.props.type} 
      name={this.props.name} 
      value={this.context.formData[this.props.name] || ""}
      autoComplete={this.props.autoComplete}
      onChange={
          this.changeVal
      }/>
    )
  }
}


// function InputNew (props){
//   return 

// }